#include "arena.h"
#include "assert.h"
#include <string.h>


void arena_dump(arena_T arena);


void
simple_test() {
	printf("enter simple test\n");
	arena_T arena;
	arena = arena_new();
	arena_dispose(&arena);

	void *ptr;
	arena = arena_new();
	ptr = arena_alloc(arena, 1000, __FILE__, __LINE__);
	memset(ptr, 'a', 1000);
	arena_free(arena);
	arena_dump(arena);

	ptr = arena_calloc(arena, 5, 1000, __FILE__, __LINE__);
	memset(ptr, 'b', 5 * 1000);
	arena_dump(arena);
	arena_dispose(&arena);
	printf("\n\n");

	arena = arena_new();
	int bytes = 0;
	for (int i = 1; i < 50000; i++) {
		bytes += i;
		ptr = arena_alloc(arena, i, __FILE__, __LINE__);
		memset(ptr, 'm', i);
	}
	arena_dump(arena);
	printf("total %.4f KiB for alloc\n", (double)bytes / 1024);
	arena_free(arena);
	printf("dump after free\n");
	arena_dump(arena);
	arena_dispose(&arena);

	printf("end simple test\n");
}

int
main() {
	simple_test();
	printf("arena test pass\n");
	return 0;
}
